#import "AliCrashReportPlugin.h"
#import <AlicloudCrash/AlicloudCrashProvider.h>
#import <AlicloudHAUtil/AlicloudHAProvider.h>

@implementation AliCrashReportPlugin
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
  FlutterMethodChannel* channel = [FlutterMethodChannel
      methodChannelWithName:@"ali_crash_report"
            binaryMessenger:[registrar messenger]];
  AliCrashReportPlugin* instance = [[AliCrashReportPlugin alloc] init];
  [registrar addMethodCallDelegate:instance channel:channel];
}

- (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
  if ([@"getPlatformVersion" isEqualToString:call.method]) {
    result([@"iOS " stringByAppendingString:[[UIDevice currentDevice] systemVersion]]);
  } else if([@"testCrash" isEqualToString:call.method]){
      NSMutableArray *array = @[];
      [array addObject:nil];
  } else if([@"updateNick" isEqualToString:call.method]){
      if(call.arguments != NULL && [call.arguments isKindOfClass:[NSString class]]){
          NSString* nick = call.arguments;
          [AliCrashReportPlugin updateNick:nick];
      }
  } else {
    result(FlutterMethodNotImplemented);
  }
}

//初始化
+ (void)init:(NSString*)appVersion channel:(NSString*)channel nick:(NSString*)nick {
    //nick 昵称，自定义，会上报
    [[AlicloudCrashProvider alloc] autoInitWithAppVersion:appVersion channel:channel nick:nick];
    [AlicloudHAProvider start];
}

//更新昵称
+ (void)updateNick:(NSString*)nick {
    [AlicloudCrashProvider updateNick:nick];
}



@end
